
//
//  HMStatusPhotoView.m
//  黑马微博-wzy
//
//  Created by Mac on 2017/2/14.
//  Copyright © 2017年 Mac. All rights reserved.
//

#import "HMStatusPhotoView.h"
#import "HMPhoto.h"
//#import "UIImageView+WebCache.h"


@interface HMStatusPhotoView()

@property (nonatomic, weak) UIImageView *gifView;

@end


@implementation HMStatusPhotoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        //对图片进行设置
        self.userInteractionEnabled = YES;
        
        //UIViewContentModeScaleToFill:图片填充,有可能变形(图片默认的属性)
        //UIViewContentModeScaleAspectFit:以图片长宽最大者为主,按比例缩放,结果可能有长方形,有正方形
        //UIViewContentModeScaleAspectFill:居中填充,多余的会被切掉(一般使用该属性)
        self.contentMode = UIViewContentModeScaleAspectFill;
        self.clipsToBounds = YES;
        
        //添加一个gif图标
        UIImage *image = [UIImage imageWithName:@"timeline_image_gif"];
        //这种情况下的创建的UIImageView的尺寸跟图片尺寸一样
        UIImageView *gifView = [[UIImageView alloc] initWithImage:image];
        [self addSubview:gifView];
        self.gifView = gifView;
        
    }
    return self;
}

- (void)setPhoto:(HMPhoto *)photo{
    _photo = photo;
    
    //1.下载图片
    [self sd_setImageWithURL:[NSURL URLWithString:photo.thumbnail_pic] placeholderImage:[UIImage imageWithName:@"timeline_image_placeholder"]];
    
    //2.控件gif图标的显示:pathExtension:扩展名
    //先全部转化为小写
    NSString *extension = photo.thumbnail_pic.pathExtension.lowercaseString;
    //如果是gif,图标显示;否则隐藏
    self.gifView.hidden = ![extension isEqualToString:@"gif"];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    //设置gifView在图片的右下角
    self.gifView.x = self.width - self.gifView.width;
    self.gifView.y = self.height - self.gifView.height;
}


@end
